package jmine.tec.aom.services.include;

import jmine.tec.aom.AOMMessages;
import jmine.tec.aom.domain.EnumProperty;
import jmine.tec.di.annotation.Injected;
import jmine.tec.services.annotations.ServiceImplementor;
import jmine.tec.services.api.ActionsEnum;
import jmine.tec.services.api.RawInput;
import jmine.tec.services.api.ServiceValidationExecutionException;
import jmine.tec.services.api.export.ReferenceMap;
import jmine.tec.services.export.impl.ExportUtils;
import jmine.tec.services.io.ServiceBean;

/**
 * Generic service for creating {@link EnumProperty}
 * 
 * @author jrenaut
 */
@ServiceImplementor(action = ActionsEnum.INCLUIR)
public class EnumPropertyService extends AbstractEnumPropertyService {

    public static final String ENUM_TYPE = "Enum type";

    private RawInput props;

    /**
     * {@inheritDoc}
     */
    @Override
    protected String getEnumClass() {
        String enumClass = this.props.getRaw(ENUM_TYPE);
        if (enumClass == null || enumClass.trim().length() == 0) {
            throw new ServiceValidationExecutionException(AOMMessages.FIELD_REQUIRED.create(ENUM_TYPE));
        }
        return enumClass;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void fillSpecificServiceBean(ServiceBean bean, ReferenceMap referenceMap, EnumProperty entity) {
        ExportUtils.put(bean, ENUM_TYPE, entity.getFullyQualifiedName());
    }

    /**
     * @param props the props to set
     */
    @Injected
    public void setProps(RawInput props) {
        this.props = props;
    }

}
